package com.lcz.mytest.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lcz.mytest.R;
import com.lcz.mytest.domain.StockList;

import java.util.List;

/**
 * Created by Administrator on 2016/4/1.
 */
public class StockListAdapter extends BaseAdapter {
    private List<StockList.ResultBean.DataBean> list = null;
    private Context context;

    public StockListAdapter(List<StockList.ResultBean.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public StockList.ResultBean.DataBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyHolder holder;
        View view = convertView;
        if (view == null) {
            holder = new MyHolder();
            view = View.inflate(context, R.layout.sz_list_item, null);
            holder.code = (TextView) view.findViewById(R.id.code);
            view.setTag(holder);
        } else {
            holder = (MyHolder) view.getTag();
        }
        holder.code.setText((position + 1) + "." + list.get(position).getName() + "(" + list.get(position).getSymbol() + ")");
        return view;
    }

    public void upDataList(List<StockList.ResultBean.DataBean> listData) {
        this.list = listData;
    }

    static class MyHolder {
        TextView code;
    }
}
